from pydantic import BaseModel, Field, ConfigDict
from typing import Optional, List
from datetime import datetime


class ToolsCreate(BaseModel):
    title: str
    url: str
    category: str
    description: Optional[str] = None
    direct_link: Optional[str] = None
    image: Optional[str] = None
    upload_by: Optional[int] = None
    is_active: Optional[bool] = True


class ToolsUpdate(BaseModel):
    title: Optional[str] = None
    url: Optional[str] = None
    category: Optional[str] = None
    description: Optional[str] = None
    direct_link: Optional[str] = None
    image: Optional[str] = None
    sort_order: Optional[int] = None
    upload_by: Optional[int] = None
    is_active: Optional[bool] = None


class ToolsResponse(BaseModel):
    id: int
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    title: Optional[str] = None
    description: Optional[str] = None
    url: Optional[str] = None
    direct_link: Optional[str] = None
    category: Optional[str] = None
    image: Optional[str] = None
    sort_order: Optional[int] = None
    upload_by: Optional[int] = None
    is_active: Optional[bool] = None
    click_count: Optional[int] = None

    model_config = ConfigDict(from_attributes=True)


class ToolsListResponse(BaseModel):
    code: int
    msg: str
    data: List[ToolsResponse]


class ToolsQuery(BaseModel):
    keyword: Optional[str] = None
    category: Optional[str] = None
    page: Optional[int] = 1
    page_size: Optional[int] = 10


class ToolsClickRequest(BaseModel):
    tool_id: int = Field(..., description="工具ID")


class DisableToolRequest(BaseModel):
    tools_id: str = Field(..., description="工具ID，支持单个ID或逗号分隔的多个ID")
    status: int = Field(..., description="工具状态，0=禁用，1=启用")